﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;


namespace Evoucher.Business
{

    /// <summary>
    /// Summary description for RemotePost
    /// </summary>
    public class RemotePost
    {
        private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();

        private string url;
        public string Method = "post";
        public string FormName = "form1";

        public RemotePost(string Url)
        {
            this.url = Url;
        }

        public void Add(string name, string value)
        {
            Inputs.Add(name, value);
        }

        public void Post(Page page)
        {

            System.Web.HttpContext.Current.Response.Write(string.Format("<form name='{0}' method='{1}' action='{2}' >", FormName, Method, url));
            for (int i = 0; i < Inputs.Keys.Count; i++)
            {
                System.Web.HttpContext.Current.Response.Write(string.Format("<input name='{0}' type='hidden' value='{1}'>", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));

            }

            System.Web.HttpContext.Current.Response.Write("<input name='test' type='text' style='display:none' value='\' />");

            System.Web.HttpContext.Current.Response.Write("</form>");

            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "submitForm", String.Format("document.{0}.submit()</script>", FormName), true);
        }
    }
}